<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2018/4/1
 * Time: 22:15
 */

namespace app\index\logic;


use app\common\model\Page;

class MoneyLogLogic
{
    /**
     * ajax获取资金记录列表
     * @param $data
     * @return mixed
     */
    public function getMoneyLogList($data){
        $map = [];
        if(!isset($data['page_size'])){
            $data['page_size'] = 10;
        }
        if(!isset($data['page_num'])){
            $data['page_num'] = 1;
        }
        if(isset($data['user_id']) && !empty($data['user_id'])){
            $map['user_id'] = $data['user_id'];
        }
        if(isset($data['money_type'])){
            $map['money_type'] = $data['money_type'];
        }
        if(isset($data['change_type'])){
            $map['change_type'] = $data['change_type'];
        }
        if(isset($data['in_out_type'])){
            $map['in_out_type'] = $data['in_out_type'];
        }
        $result = $this->queryByMap($map,$data['page_num'],$data['page_size']);
        return $result;
    }

    private function queryByMap($map,$page_num,$page_size){
        $startno = ($page_num - 1) * $page_size;
        $list = model('MoneyLog')
            ->where($map)
            ->limit($startno,$page_size)
            ->order('id','desc')
            ->select();
        $count = model('MoneyLog')
            ->where($map)
            ->count();
        $result['list'] = $list;
        $page = new Page($page_num,$count,$page_size);
        $result['page'] = $page;
        return $result;
    }
}